subroutine check_readextn(lunit)
  use param
  use global_param,only:n_ext
  use global_param,only:extern_type
  use label_data_param,only:obj_type
  implicit none

  integer,intent(in) :: lunit
  
  integer :: i,j,k,n,w,pos1,pos2,flag,in1,in2,in3
  character(len=len_linebuf) :: str

  if (n_ext.eq.0) return

  in1=1
  in2=2
  in3=3
  w=15

  call log_msg1(lunit,"")
  write(str,&
       '("Information for external events.. (n_ext=",i1,")")') n_ext
  call log_msg1(lunit,str)
  call log_msg1(lunit,"")

  do i=1,n_ext

     pos1=1
     pos2=pos1+5
     write(str(pos1:pos2),'("[",i2.2,"]",1x)') i
     pos1=pos2

     ! Type of external event (1/2/3)
     flag=extern_type(i)%event_type
     select case(flag)
     case(1)

        ! Event type = neutron
        pos2=pos1+17
        write(str(pos1+1:pos2),&
             '("etype=",i1,1x,"(neutron)")') flag
        pos1=pos2

        call log_msg1_indent(lunit,in1,str(1:pos2))

        ! CDF for cascade samples
        call log_msg1(lunit,"")
        write(str,&
             '("> CDF for cascade samples",1x,"(", &
             "No. of bins=",i3,")")') &
             extern_type(i)%n_cas
        call log_msg1_indent(lunit,in1,str)

        ! e2   R   S
        pos1=0
        pos2=pos1+w
        write(str(pos1+1:pos2),'(6x,"e_2",6x)')
        pos1=pos2
        pos2=pos1+w
        write(str(pos1+1:pos2),'(7x,"R",7x)')
        pos1=pos2
        pos2=pos1+w
        write(str(pos1+1:pos2),'(7x,"S",7x)')
        call log_msg1_indent(lunit,in1,str(1:pos2))

        do j=1,extern_type(i)%n_cas
           ! print the energy, probability, number of samples
           pos1=0
           pos2=pos1+w
           write(str(pos1+1:pos2),'(1x,1pe13.5,1x)') &
                extern_type(i)%cgrid(j)
           pos1=pos2

           pos2=pos1+w
           write(str(pos1+1:pos2),'(1x,1pe13.5,1x)') &
                extern_type(i)%cprob(j)
           pos1=pos2

           pos2=pos1+w
           write(str(pos1+1:pos2),'(i3,12x)') &
                extern_type(i)%cascade_list(j)%nlist
           pos1=pos2

           ! show the list of cascade samples in this group
           do k=1,extern_type(i)%cascade_list(j)%nlist
              if (k.eq.1) then
                 pos2=pos1+1
                 write(str(pos1+1:pos2),'("(")')
                 pos1=pos2
              end if

              pos2=pos1+3
              write(str(pos1+1:pos2),'(i2,1x)') &
                   extern_type(i)%cascade_list(j)%clist(k)
              pos1=pos2

              if (k.eq.extern_type(i)%cascade_list(j)%nlist) then
                 pos2=pos1+1
                 write(str(pos1+1:pos2),'(")")')
                 pos1=pos2
              end if
           end do

           call log_msg1_indent(lunit,in1,str(1:pos2))

        end do

        ! CDF for dpa measurement
        call log_msg1(lunit,"")
        write(str,&
             '("> CDF for dpa measurement",1x,"(", &
             "No. of bins=",i3,")")') &
             extern_type(i)%n_dpa
        call log_msg1_indent(lunit,in1,str)

        ! e  R
        pos1=0
        pos2=pos1+w
        write(str(pos1+1:pos2),'(6x,"e_2",6x)')
        pos1=pos2
        pos2=pos1+w
        write(str(pos1+1:pos2),'(7x,"R",7x)')
        call log_msg1_indent(lunit,in1,str(1:pos2))

        do j=1,extern_type(i)%n_dpa
           pos1=0
           pos2=pos1+w
           write(str(pos1+1:pos2),'(1x,1pe13.5,1x)') &
                extern_type(i)%dgrid(j)
           pos1=pos2

           pos2=pos1+w
           write(str(pos1+1:pos2),'(1x,1pe13.5,1x)') &
                extern_type(i)%dprob(j)
           pos1=pos2

           call log_msg1_indent(lunit,in1,str(1:pos2))
        end do

        ! Show cascade samples
        call log_msg1(lunit,"")
        write(str,'("> Sets of cascade samples",1x,i0)') &
             extern_type(i)%n_objset
        call log_msg1_indent(lunit,in1,str)

        do j=1,extern_type(i)%n_objset

           ! show the head of the set
           pos1=0
           pos2=pos1+20
           write(str(pos1+1:pos2),'("PKA_E=",1pe13.5,1x)') &
                extern_type(i)%objset(j)%pka_e
           pos1=pos2

           pos2=pos1+20
           write(str(pos1+1:pos2),'("No. of objects=",i5)') &
                extern_type(i)%objset(j)%n_obj

           call log_msg1_indent(lunit,in2,str(1:pos2))

           ! show the list
           do k=1,extern_type(i)%objset(j)%n_obj

              pos1=0
              pos2=pos1+8
              write(str(pos1+1:pos2),'("[",i5.5,"]",1x)') k
              pos1=pos2

              pos2=pos1+12
              n=extern_type(i)%objset(j)%obj(k)%obj_type
              write(str(pos1+1:pos2),'(1x,a10,1x)') &
                   obj_type(n)%name
              pos1=pos2

              pos2=pos1+17
              write(str(pos1+1:pos2),'("px=",1pe13.5,1x)') &
                   extern_type(i)%objset(j)%obj(k)%pos(1)
              pos1=pos2

              pos2=pos1+17
              write(str(pos1+1:pos2),'("py=",1pe13.5,1x)') &
                   extern_type(i)%objset(j)%obj(k)%pos(2)
              pos1=pos2

              pos2=pos1+17
              write(str(pos1+1:pos2),'("pz=",1pe13.5,1x)') &
                   extern_type(i)%objset(j)%obj(k)%pos(3)
              pos1=pos2

              n=extern_type(i)%objset(j)%obj(k)%dir
              pos2=pos1+6
              write(str(pos1+1:pos2),'("dir=",i1,1x)') n
              pos1=pos2

              if (n.eq.0) then

                 pos2=pos1+2
                 write(str(pos1+1:pos2),'(spi2)') &
                      int(extern_type(i)%objset(j)%obj(k)%vec(1))
                 pos1=pos2

                 pos2=pos1+2
                 write(str(pos1+1:pos2),'(spi2)') &
                      int(extern_type(i)%objset(j)%obj(k)%vec(2))
                 pos1=pos2

                 pos2=pos1+2
                 write(str(pos1+1:pos2),'(spi2)') &
                      int(extern_type(i)%objset(j)%obj(k)%vec(3))
                 pos1=pos2

              end if

              call log_msg1_indent(lunit,in3,str(1:pos2))

           end do

        end do

     case(2)
        ! ion

     case(3)

        ! Event type = electron
        pos2=pos1+18
        write(str(pos1+1:pos2),&
             '("etype=",i1,1x,"(electron)")') flag
        pos1=pos2

        call log_msg1_indent(lunit,in1,str(1:pos2))

        ! The types of created objects
        pos1=0
        pos2=pos1+14
        write(str(pos1+1:pos2),&
             '("No. of types=",i1)') &
             extern_type(i)%n_type
        pos1=pos2

        pos2=pos1+10
        write(str(pos1+1:pos2),'(10x)')
        pos1=pos2

        do j=1,extern_type(i)%n_type
           pos2=pos1+18
           write(str(pos1+1:pos2),&
                '(a5,"(",i5,"),",5x)') &
                trim(extern_type(i)%source_name(j)),&
                extern_type(i)%source_type(j)
           pos1=pos2
        end do

        call log_msg1_indent(lunit,in1,str(1:pos2))        

        ! distance between objects created by electron
        ! irradiation
        write(lunit,'(1x,"distance between objects = ",f4.2,&
             "~",f4.2,1x,"(nm)")') &
             extern_type(i)%dist(1),&
             extern_type(i)%dist(2)

        ! CDF for dpa measurement
        call log_msg1(lunit,"")

        write(str,&
             '("> CDF for dpa measurement",1x,"(", &
             "No. of bins=",i3,")")') &
             extern_type(i)%n_dpa
        call log_msg1_indent(lunit,in1,str)

        ! e  R
        pos1=0
        pos2=pos1+w
        write(str(pos1+1:pos2),'(6x,"e_2",6x)')
        pos1=pos2
        pos2=pos1+w
        write(str(pos1+1:pos2),'(7x,"R",7x)')
        call log_msg1_indent(lunit,in1,str(1:pos2))

        do j=1,extern_type(i)%n_dpa
           pos1=0
           pos2=pos1+w
           write(str(pos1+1:pos2),'(1x,1pe13.5,1x)') &
                extern_type(i)%dgrid(j)
           pos1=pos2

           pos2=pos1+w
           write(str(pos1+1:pos2),'(1x,1pe13.5,1x)') &
                extern_type(i)%dprob(j)
           pos1=pos2

           call log_msg1_indent(lunit,in1,str(1:pos2))
        end do

     end select

  end do

  return

end subroutine check_readextn
